using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Requerimientos", new WebServiceHostFactory(), typeof(RequerimientosService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class RequerimientosService : BaseService
    {

        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(Requerimientos Requerimiento)
        {
            Provider.AddToRequerimientos(Requerimiento);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Requerimientos.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public Requerimientos GetById(int Id)
        {
            return Provider.Requerimientos.First(i => i.IdRequerimiento == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(Requerimientos Requerimiento)
        {
            Requerimientos miRequerimiento = Provider.Requerimientos.Where(t => t.IdRequerimiento == Requerimiento.IdRequerimiento).First();
            miRequerimiento.Copy(Requerimiento);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "Delete", Method = "POST")]
        public bool Delete(int IdRequerimiento)
        {
            Provider.Requerimientos.DeleteObject(Provider.Requerimientos.Where(t => t.IdRequerimiento == IdRequerimiento).First());
            return Provider.TrySaveChanges();
        }

    }
}